package com.qys.livesMall.shop.controller.sys;

import com.qys.livesMall.common.result.R;
import com.qys.livesMall.common.utils.bean.BeanProUtils;
import com.qys.livesMall.shop.modal.vo.ShopOtherConfigVO;
import com.qys.livesMall.system.model.entity.H2SysConfig;
import com.qys.livesMall.system.service.IH2SysConfigService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @menu SysShopOtherConfigController
 * @date 2023/11/14 10:10
 */
@RestController
@RequestMapping("/sys/shop/other/config")
public class SysShopOtherConfigController {

    @Autowired
    private IH2SysConfigService sysConfigService;

    /**
     * 获取参数
     * @return
     */
    @GetMapping("/get")
    public R<List<ShopOtherConfigVO>> get(){
        List<String> keys=new ArrayList<>();
        keys.add("shop_register_reward");
        keys.add("shop_first_recharge_reward");
        keys.add("shop_invite_reward");
        List<H2SysConfig> configs=sysConfigService.getConfigByKeys(keys);
        return R.ok(BeanProUtils.copyListPropertiesV2(configs, ShopOtherConfigVO.class));
    }

    /**
     * 修改
     * @param config
     * @return
     */
    @PostMapping("/edit")
    public R edit(@RequestBody ShopOtherConfigVO config){
        H2SysConfig up=BeanProUtils.copyProperties(config,H2SysConfig::new);
        sysConfigService.updateById(up);
        return R.ok();
    }

}

